

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>Github远程仓库 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-03-10 18:09" pubdate>
        2020年3月10日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.7k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      26
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">Github远程仓库</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="Github"><a href="#Github" class="headerlink" title="Github"></a>Github</h2><p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E5%9B%BE%E6%A0%87.jpg" srcset="/img/loading.gif"></p>
<ul>
<li>概述<ul>
<li>GitHub是一个面向开源及私有软件项目的托管平台，因为只支持git 作为唯一的版本库格式进行托管。</li>
</ul>
</li>
<li>功能 <ul>
<li>代码托管</li>
<li>提供了订阅、讨论组、文本渲染、在线文件编辑器、协作图谱（报表）、代码片段分享（Gist）等功能<br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/Github.png" srcset="/img/loading.gif"></li>
</ul>
</li>
</ul>
<h2 id="Git本地仓库上传到Github"><a href="#Git本地仓库上传到Github" class="headerlink" title="Git本地仓库上传到Github"></a>Git本地仓库上传到Github</h2><ul>
<li><p>准备:</p>
<p>   linux主机 | IP:192.168.100.203</p>
<pre><code>---      |       ---</code></pre>
<ul>
<li><p>Github创建仓库<br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%931.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>创建仓库名hello wrold,选择私有仓库</p>
</blockquote>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%932.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>创建后显示</p>
</blockquote>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E5%88%9B%E5%BB%BA%E4%BB%93%E5%BA%933.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>linux主机生成秘钥复制到Github</p>
</blockquote>
<pre><code class="hljs gherkin">[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># ssh-keygen </span>
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory &#x27;/root/.ssh&#x27;.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:3vlxpFBcufj9iMUYZI6WnRAPnstSt1eaZVMk3yEN718 root<span class="hljs-meta">@localhost.localdomain</span>
The key&#x27;s randomart image is:
+---[RSA 2048]----+
|<span class="hljs-string">          o. o=+o</span>|
|<span class="hljs-string">         ..=o.+++</span>|
|<span class="hljs-string">          +O=o +*</span>|
|<span class="hljs-string">         o++*.o*.</span>|
|<span class="hljs-string">        S.+ .==oE</span>|
|<span class="hljs-string">       . o o.++ +</span>|
|<span class="hljs-string">        . o oo..o</span>|
|<span class="hljs-string">           ..o. .</span>|
|<span class="hljs-string">            .    </span>|
+----[SHA256]-----+
[root<span class="hljs-meta">@localhost</span> ~]<span class="hljs-comment"># cat /root/.ssh/id_rsa.pub </span>
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClrxAabHK6unM+7HpIhf6fQTMx0byvGRmCBYxPTucGq+TsSFY+XDAfXwD1181Dm8tSUpWs/4m7zhZPeCMrIag7I7BBIk6yBD0o1JslHF7O31qgQgn1Bd7WV0aKKYZDeye77i1IeBJ0KklUJpYcTulyeuyFXQL93Uy50vMwUpGw7KOq9L4/m6dYkD/Ex4pVk6RQnD2xE2pJ686WQ+fNTy5T2k5TAZNWW8cLAFcCir5ECeg9mUgkfc7q4HeZut6gDfcMw1ufcRX5pD5q1nizmXdqhrXblGclWIFRaZ4DZ2t5F5QHU4UDbD3uA47nHx24f/MbpMYSLBT6AM0bjUYyGZDZ root<span class="hljs-meta">@localhost.localdomain</span>
<span class="hljs-comment"># 把上面一行公钥复制到github</span></code></pre>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/Github%E9%85%8D%E7%BD%AE%E7%A7%98%E9%92%A51.png" srcset="/img/loading.gif"><br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/Github%E9%85%8D%E7%BD%AE%E7%A7%98%E9%92%A52.png" srcset="/img/loading.gif"><br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/Github%E9%85%8D%E7%BD%AE%E7%A7%98%E9%92%A53.png" srcset="/img/loading.gif"><br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/Github%E9%85%8D%E7%BD%AE%E7%A7%98%E9%92%A54.png" srcset="/img/loading.gif"></p>
<p>复制github的url</p>
<blockquote>
<p><a href="mailto:&#103;&#x69;&#x74;&#64;&#x67;&#105;&#116;&#104;&#117;&#x62;&#x2e;&#x63;&#x6f;&#x6d;">&#103;&#x69;&#x74;&#64;&#x67;&#105;&#116;&#104;&#117;&#x62;&#x2e;&#x63;&#x6f;&#x6d;</a>:LMK-hacker/hello-world.git </p>
</blockquote>
<p>添加远程仓库</p>
<pre><code class="hljs ruby">[root@localhost test]<span class="hljs-comment"># git remote add origin git<span class="hljs-doctag">@github</span>.com:LMK-hacker/hello-world.git  # origin 指定源文件地址</span></code></pre>
<p>上传本地仓库的文件</p>
<pre><code class="hljs autoit">[root<span class="hljs-symbol">@localhost</span> test]<span class="hljs-meta"># ls</span>
hello.txt</code></pre>
<pre><code class="hljs yaml">[<span class="hljs-string">root@localhost</span> <span class="hljs-string">test</span>]<span class="hljs-comment"># git push -u origin master # 把文件传到袁成成主机的master主干上 -u 第一次上传时需要写入，以后就不用了</span>
<span class="hljs-string">The</span> <span class="hljs-string">authenticity</span> <span class="hljs-string">of</span> <span class="hljs-string">host</span> <span class="hljs-string">&#x27;github.com (13.229.188.59)&#x27;</span> <span class="hljs-string">can&#x27;t</span> <span class="hljs-string">be</span> <span class="hljs-string">established.</span>
<span class="hljs-string">RSA</span> <span class="hljs-string">key</span> <span class="hljs-string">fingerprint</span> <span class="hljs-string">is</span> <span class="hljs-string">SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.</span>
<span class="hljs-string">RSA</span> <span class="hljs-string">key</span> <span class="hljs-string">fingerprint</span> <span class="hljs-string">is</span> <span class="hljs-string">MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.</span>
<span class="hljs-string">Are</span> <span class="hljs-string">you</span> <span class="hljs-string">sure</span> <span class="hljs-string">you</span> <span class="hljs-string">want</span> <span class="hljs-string">to</span> <span class="hljs-string">continue</span> <span class="hljs-string">connecting</span> <span class="hljs-string">(yes/no)?</span> <span class="hljs-literal">yes</span>
<span class="hljs-attr">Warning:</span> <span class="hljs-string">Permanently</span> <span class="hljs-string">added</span> <span class="hljs-string">&#x27;github.com,13.229.188.59&#x27;</span> <span class="hljs-string">(RSA)</span> <span class="hljs-string">to</span> <span class="hljs-string">the</span> <span class="hljs-string">list</span> <span class="hljs-string">of</span> <span class="hljs-string">known</span> <span class="hljs-string">hosts.</span>
<span class="hljs-attr">Counting objects:</span> <span class="hljs-number">3</span><span class="hljs-string">,</span> <span class="hljs-string">done.</span>
<span class="hljs-attr">Writing objects:</span> <span class="hljs-number">100</span><span class="hljs-string">%</span> <span class="hljs-string">(3/3),</span> <span class="hljs-number">202</span> <span class="hljs-string">bytes</span> <span class="hljs-string">|</span> <span class="hljs-number">0</span> <span class="hljs-string">bytes/s,</span> <span class="hljs-string">done.</span>
<span class="hljs-string">Total</span> <span class="hljs-number">3</span> <span class="hljs-string">(delta</span> <span class="hljs-number">0</span><span class="hljs-string">),</span> <span class="hljs-string">reused</span> <span class="hljs-number">0</span> <span class="hljs-string">(delta</span> <span class="hljs-number">0</span><span class="hljs-string">)</span>
<span class="hljs-string">To</span> <span class="hljs-string">git@github.com:LMK-hacker/hello-world.git</span>
 <span class="hljs-string">*</span> [<span class="hljs-string">new</span> <span class="hljs-string">branch</span>]      <span class="hljs-string">master</span> <span class="hljs-string">-&gt;</span> <span class="hljs-string">master</span>
<span class="hljs-string">分支</span> <span class="hljs-string">master</span> <span class="hljs-string">设置为跟踪来自</span> <span class="hljs-string">origin</span> <span class="hljs-string">的远程分支</span> <span class="hljs-string">master。</span></code></pre>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/git%E4%B8%8A%E4%BC%A0github.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>创建本地git仓库—&gt; 添加暂存区—&gt;提交到本地仓库—&gt;从本地仓库上传到远程仓库 (创建本地仓库上一章有写)</p>
</blockquote>
</li>
</ul>
</li>
</ul>
<h2 id="Git仓库克隆"><a href="#Git仓库克隆" class="headerlink" title="Git仓库克隆"></a>Git仓库克隆</h2><pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost ~]</span># git clone <span class="hljs-symbol">git@</span>github.com:LMK-hacker/hello-world.git
正克隆到 <span class="hljs-string">&#x27;hello-world&#x27;</span>...
remote: Enumerating objects: <span class="hljs-number">3</span>, done.
remote: Counting objects: <span class="hljs-number">100</span>% (<span class="hljs-number">3</span>/<span class="hljs-number">3</span>), done.
remote: Total <span class="hljs-number">3</span> (delta <span class="hljs-number">0</span>), reused <span class="hljs-number">3</span> (delta <span class="hljs-number">0</span>), pack-reused <span class="hljs-number">0</span>
接收对象中: <span class="hljs-number">100</span>% (<span class="hljs-number">3</span>/<span class="hljs-number">3</span>), done.
<span class="hljs-string">[root@localhost ~]</span># ls hello-world/
hello.txt</code></pre>
<blockquote>
<p>如果在操作时把github远程仓库上的某个文件删除了，再次上传push时的时候会不允许上传，出现这种情况可能是数据紊乱</p>
</blockquote>
<blockquote>
<p>以下是出现错误时操作</p>
</blockquote>
<pre><code class="hljs autoit">[root<span class="hljs-symbol">@localhost</span> ~]<span class="hljs-meta"># cd hello-world/</span>
[root<span class="hljs-symbol">@localhost</span> hello-world]<span class="hljs-meta"># echo 123 &gt;&gt; hello.txt </span>
[root<span class="hljs-symbol">@localhost</span> hello-world]<span class="hljs-meta"># git add hello.txt # 添加到暂存区</span>
[root<span class="hljs-symbol">@localhost</span> hello-world]<span class="hljs-meta"># git commit -m <span class="hljs-string">&quot;123&quot;</span> # 添加到本地仓库</span>
[master a056585] <span class="hljs-number">123</span>
 <span class="hljs-number">1</span> file changed, <span class="hljs-number">1</span> insertion(+)
[root<span class="hljs-symbol">@localhost</span> hello-world]<span class="hljs-meta"># git push origin master # 提交到远程仓库</span>
Warning: Permanently added the RSA host key <span class="hljs-keyword">for</span> IP address <span class="hljs-string">&#x27;52.74.223.119&#x27;</span> <span class="hljs-keyword">to</span> the list of known hosts.
<span class="hljs-keyword">To</span> git<span class="hljs-symbol">@github</span>.com:LMK-hacker/hello-world.git
 ! [rejected]        master -&gt; master (fetch first)
error: 无法推送一些引用到 <span class="hljs-string">&#x27;git@github.com:LMK-hacker/hello-world.git&#x27;</span>
提示：更新被拒绝，因为远程版本库包含您本地尚不存在的提交。这通常是因为另外
提示：一个版本库已推送了相同的引用。再次推送前，您可能需要先合并远程变更
提示：（如 <span class="hljs-string">&#x27;git pull&#x27;</span>）。
提示：详见 <span class="hljs-string">&#x27;git push --help&#x27;</span> 中的 <span class="hljs-string">&#x27;Note about fast-forwards&#x27;</span> 小节。
[root<span class="hljs-symbol">@localhost</span> hello-world]<span class="hljs-meta">#</span></code></pre>
<blockquote>
<p>解决方法</p>
</blockquote>
<pre><code class="hljs crmsh">git pull
git push origin <span class="hljs-literal">master</span>
或
git push origin <span class="hljs-keyword">master</span> <span class="hljs-title">--force</span> <span class="hljs-comment"># --force可能导致数据不稳定</span>
</code></pre>
<h2 id="标签管理"><a href="#标签管理" class="headerlink" title="标签管理"></a>标签管理</h2><p>  tag 对于仓库来说就相当于虚拟机的快照</p>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost hello-world]</span># git tag # 查看标签
<span class="hljs-string">[root@localhost hello-world]</span># git tag v0<span class="hljs-number">.1</span> # 创建标签
<span class="hljs-string">[root@localhost hello-world]</span># git tag # 查看标签
v0<span class="hljs-number">.1</span>
<span class="hljs-string">[root@localhost hello-world]</span># git push origin v0<span class="hljs-number">.1</span> # 将标签上传到远程
Total <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>), reused <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>)
To <span class="hljs-symbol">git@</span>github.com:LMK-hacker/hello-world.git
 * [new tag]         v0<span class="hljs-number">.1</span> -&gt; v0<span class="hljs-number">.1</span></code></pre>
<blockquote>
<p>查看github仓库的标签</p>
</blockquote>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E6%9F%A5%E7%9C%8B%E6%A0%87%E7%AD%BE.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>通过标签实现回溯代码</p>
</blockquote>
 <pre><code class="hljs angelscript"># 在上一章创建的本地仓库上传到远程仓库 仓库地址/tmp/test
<span class="hljs-string">[root@localhost test]</span># echo lll &gt; lll.txt
<span class="hljs-string">[root@localhost test]</span># git add lll.txt # 添加到暂存区
<span class="hljs-string">[root@localhost test]</span># git commit -m <span class="hljs-string">&quot;2&quot;</span> # 提交到本地仓库
<span class="hljs-string">[master b62d93d]</span> <span class="hljs-number">2</span>
<span class="hljs-number">1</span> file changed, <span class="hljs-number">1</span> insertion(+)
create mode <span class="hljs-number">100644</span> lll.txt
<span class="hljs-string">[root@localhost test]</span># git push origin master # 上传文件到远程仓库
Counting objects: <span class="hljs-number">6</span>, done.
Delta compression using up to <span class="hljs-number">4</span> threads.
Compressing objects: <span class="hljs-number">100</span>% (<span class="hljs-number">3</span>/<span class="hljs-number">3</span>), done.
Writing objects: <span class="hljs-number">100</span>% (<span class="hljs-number">6</span>/<span class="hljs-number">6</span>), <span class="hljs-number">424</span> bytes | <span class="hljs-number">0</span> bytes/s, done.
Total <span class="hljs-number">6</span> (delta <span class="hljs-number">0</span>), reused <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>)
To <span class="hljs-symbol">git@</span>github.com:LMK-hacker/hello-world.git
+ a056585...b62d93d master -&gt; master (forced update)
<span class="hljs-string">[root@localhost test]</span># ls
hello.txt  lll.txt
<span class="hljs-string">[root@localhost test]</span># git tag v0<span class="hljs-number">.2</span> # 创建标签
<span class="hljs-string">[root@localhost test]</span># git push origin v0<span class="hljs-number">.2</span> # 上传标签
Total <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>), reused <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>) 
To <span class="hljs-symbol">git@</span>github.com:LMK-hacker/hello-world.git
* [new tag]         v0<span class="hljs-number">.2</span> -&gt; v0<span class="hljs-number">.2</span>
<span class="hljs-string">[root@localhost test]</span># git tag # 查看标签
v0<span class="hljs-number">.2</span></code></pre>
<blockquote>
<p>查看标签</p>
</blockquote>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/github%E6%9F%A5%E7%9C%8B%E6%A0%87%E7%AD%BE2.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>点击标签可以回溯到标签的状态</p>
</blockquote>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/%E6%A0%87%E7%AD%BE%E5%9B%9E%E6%BA%AF.png" srcset="/img/loading.gif"></p>
<h2 id="分支管理"><a href="#分支管理" class="headerlink" title="分支管理"></a>分支管理</h2><p>  Git每个分支可以放不同的代码，创建其他分支是为了保证代码没有错误，然后再合并到主分支</p>
<blockquote>
<p>创建分支</p>
</blockquote>
<pre><code class="hljs crmsh">[root@localhost test]<span class="hljs-comment"># git branch # 查看分支</span>
* <span class="hljs-literal">master</span>
[root@localhost test]<span class="hljs-comment"># git branch salve # 创建 salve分支</span>
[root@localhost test]<span class="hljs-comment"># git branch # 查看分支</span>
* <span class="hljs-literal">master</span>
  salve
[root@localhost test]<span class="hljs-comment"># git checkout salve # 切换分支</span>
切换到分支 &#x27;salve&#x27;</code></pre>
<blockquote>
<p>分支创建内容并上传到github</p>
</blockquote>
<pre><code class="hljs yaml">[<span class="hljs-string">root@localhost</span> <span class="hljs-string">test</span>]<span class="hljs-comment"># echo lmkl &gt; lmk.txt</span>
[<span class="hljs-string">root@localhost</span> <span class="hljs-string">test</span>]<span class="hljs-comment"># git add lmk.txt</span>
[<span class="hljs-string">root@localhost</span> <span class="hljs-string">test</span>]<span class="hljs-comment"># git commit -m &quot;lmk&quot;</span>
[<span class="hljs-string">salve</span> <span class="hljs-string">e6172f6</span>] <span class="hljs-string">lmk</span>
 <span class="hljs-number">1</span> <span class="hljs-string">file</span> <span class="hljs-string">changed,</span> <span class="hljs-number">1</span> <span class="hljs-string">insertion(+)</span>
 <span class="hljs-string">create</span> <span class="hljs-string">mode</span> <span class="hljs-number">100644</span> <span class="hljs-string">lmk.txt</span>
[<span class="hljs-string">root@localhost</span> <span class="hljs-string">test</span>]<span class="hljs-comment"># git push origin salve</span>
<span class="hljs-attr">Counting objects:</span> <span class="hljs-number">4</span><span class="hljs-string">,</span> <span class="hljs-string">done.</span>
<span class="hljs-string">Delta</span> <span class="hljs-string">compression</span> <span class="hljs-string">using</span> <span class="hljs-string">up</span> <span class="hljs-string">to</span> <span class="hljs-number">4</span> <span class="hljs-string">threads.</span>
<span class="hljs-attr">Compressing objects:</span> <span class="hljs-number">100</span><span class="hljs-string">%</span> <span class="hljs-string">(2/2),</span> <span class="hljs-string">done.</span>
<span class="hljs-attr">Writing objects:</span> <span class="hljs-number">100</span><span class="hljs-string">%</span> <span class="hljs-string">(3/3),</span> <span class="hljs-number">286</span> <span class="hljs-string">bytes</span> <span class="hljs-string">|</span> <span class="hljs-number">0</span> <span class="hljs-string">bytes/s,</span> <span class="hljs-string">done.</span>
<span class="hljs-string">Total</span> <span class="hljs-number">3</span> <span class="hljs-string">(delta</span> <span class="hljs-number">0</span><span class="hljs-string">),</span> <span class="hljs-string">reused</span> <span class="hljs-number">0</span> <span class="hljs-string">(delta</span> <span class="hljs-number">0</span><span class="hljs-string">)</span>
<span class="hljs-attr">remote:</span> 
<span class="hljs-attr">remote:</span> <span class="hljs-string">Create</span> <span class="hljs-string">a</span> <span class="hljs-string">pull</span> <span class="hljs-string">request</span> <span class="hljs-string">for</span> <span class="hljs-string">&#x27;salve&#x27;</span> <span class="hljs-attr">on GitHub by visiting:</span>
<span class="hljs-attr">remote:</span>      <span class="hljs-string">https://github.com/LMK-hacker/hello-world/pull/new/salve</span>
<span class="hljs-attr">remote:</span> 
<span class="hljs-string">To</span> <span class="hljs-string">git@github.com:LMK-hacker/hello-world.git</span>
 <span class="hljs-string">*</span> [<span class="hljs-string">new</span> <span class="hljs-string">branch</span>]      <span class="hljs-string">salve</span> <span class="hljs-string">-&gt;</span> <span class="hljs-string">salve</span></code></pre>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/salve%E5%88%86%E6%94%AF.png" srcset="/img/loading.gif"><br>查看分支内的东西<br><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/salve%E5%88%86%E6%94%AF2.png" srcset="/img/loading.gif"></p>
<p>合并分支</p>
<pre><code class="hljs crmsh">[root@localhost test]<span class="hljs-comment"># git branch # 查看分支</span>
  <span class="hljs-literal">master</span>
* salve
[root@localhost test]<span class="hljs-comment"># git checkout master  # 切换分支</span>
切换到分支 &#x27;<span class="hljs-literal">master</span>&#x27;
[root@localhost test]<span class="hljs-comment"># git branch  # 查看分支</span>
* <span class="hljs-literal">master</span>
  salve
[root@localhost test]<span class="hljs-comment"># git merge salve  # 合并分支 在master合并salve分支</span>
更新 b62d93d..e6172f6
Fast-forward
 lmk.txt | <span class="hljs-number">1</span> +
 <span class="hljs-number">1</span> file changed, <span class="hljs-number">1</span> insertion(+)
 create mode <span class="hljs-number">100644</span> lmk.txt
</code></pre>
<p>合并分支后切换到master分支</p>
<pre><code class="hljs angelscript"><span class="hljs-string">[root@localhost test]</span># ls # 现在主分支多了个文件
hello.txt  lll.txt  lmk.txt
<span class="hljs-string">[root@localhost test]</span># git push origin master  上传到远程仓库
Total <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>), reused <span class="hljs-number">0</span> (delta <span class="hljs-number">0</span>)
To <span class="hljs-symbol">git@</span>github.com:LMK-hacker/hello-world.git
   b62d93d..e6172f6  master -&gt; master</code></pre>
<p><img src="/images/Git%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/master%E5%88%86%E6%94%AF.png" srcset="/img/loading.gif"></p>
<ul>
<li>在linux主机合并分支后，只是合并的本地仓库的文件，需要再把主分支的文件在push到远程仓库.</li>
<li>如果没有合并分支，其他分支无论怎么删除和修改，都不影响主分支</li>
</ul>
<h2 id="小结"><a href="#小结" class="headerlink" title="小结"></a>小结</h2><p> 不知不觉写了一下午了现在是晚上九点，效率有点慢呀哈哈，万事开头难，加油吧!</p>
<p> 下一章</p>
<ul>
<li>Gitlab远程仓库</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84/">微服务架构</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Git/">Git</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/03/14/gitlab%E8%BF%9C%E7%A8%8B%E4%BB%93%E5%BA%93/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">gitlab远程仓库</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/03/10/git%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6%E7%B3%BB%E7%BB%9F/">
                        <span class="hidden-mobile">Git版本控制系统</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Github远程仓库&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
